package brad.zimmerman.dungeon.game;


public class ClassUnlockable {
	ClassDrawingHolder Draws = new ClassDrawingHolder();
	private boolean[] classUsed,levelUsed;
	private int[] enemyUnlockableLevel;
	private int level;
	
	ClassUnlockable(int level){
		this.level = level;
		this.classUsed = new boolean[Draws.classStrings.length];
		this.levelUsed = new boolean[Draws.levelStrings.length];
		this.enemyUnlockableLevel = new int[Draws.enemyStrings.length];
		setLevelFirstSeen();
	}
	
	public int convertEnemyPos(int position){
		int count = 0 ;
		for(int i = 0 ; i < enemyUnlockableLevel.length;i++){
			if(enemyUnlockableLevel[i]<=level+1){
				if(position == count){
					return i;
				}
				count++;
			}
		}
		return 0;
	}
	
	public int convertClassPos(int position){
		int count = 0 ;
		for(int i = 0 ; i < Draws.unlockLevels.length;i++){
			if(Draws.unlockLevels[i]<=level){
				if(position == count){
					return i;
				}
				count++;
			}
		}
		return 0;
	}
	
	public void setUsedClasses(boolean[] holder){
		for(int i = 0 ; i < holder.length;i++){
			classUsed[i] = holder[i];
			//System.out.println("Class: " + i + " Value: " +holder[i]);
		}
	}
	
	public void setUsedLevels(boolean[] holder){
		for(int i = 0 ; i < holder.length;i++){
			levelUsed[i] = holder[i];
			//System.out.println("Level: " + i + " Value: " +holder[i]);
		}
	}
	
	public int getMonsterCount(){
		int count = 0;
		for(int i = 0; i< enemyUnlockableLevel.length;i++){
			if(enemyUnlockableLevel[i]<=level+1){
				count++;
			}
		}
		return count;
	}
	
	public int returnGlyphCount(){
		int count = 0;
		for(int i =0; i<Draws.glyphImages.length;i++){
			if(i!=2 && Draws.glyphUnlocked(i,level)){
				count++;
			}
		}
		return count;
	}
	
	public int[] getGlyphImages(){
		int[] holder = new int[Draws.glyphImages.length];
		int k =0;
		for(int i = 0; i< Draws.glyphImages.length;i++){
			if(i!=2 && Draws.glyphUnlocked(i,level)){
				holder[k] = Draws.glyphImages[i];
				k++;
			}
		}
		return holder;
	}
	
	public int convertGlyphPos(int position){
		int count = 0 ;
		for(int i = 0 ; i < Draws.glyphImages.length;i++){
			if(i!=2 && Draws.glyphUnlocked(i,level)){
				if(position == count){
					return i;
				}
				count++;
			}
		}
		return 0;
	}
	
	public int[] getMonsterImages(){
		int[] holder = new int[Draws.enemyImages.length];
		int k =0;
		for(int i = 0; i< Draws.enemyImages.length;i++){
			if(enemyUnlockableLevel[i]<=level+1){
				holder[k] = Draws.enemyImages[i];
				k++;
			}
		}
		return holder;
	}
	
	public void setLevelFirstSeen(){
		for(int i = 0; i< enemyUnlockableLevel.length;i++){
			enemyUnlockableLevel[i]=-1;
		}
		for(int stage = 0; stage < Draws.levelMonsters.length;stage++){
			for(int monster = 0;monster < 4;monster++){
				if(enemyUnlockableLevel[Draws.levelMonsters[stage][monster]] == -1){
					enemyUnlockableLevel[Draws.levelMonsters[stage][monster]] = stage;
				}
			}
			
		}
	}
	
	public boolean getLevelUsed(int position){
		return levelUsed[position];
	}
	
	public void setLevelUsed(boolean value, int position){
		levelUsed[position] = value;
	}
	
	public boolean getClassUsed(int position){
		return classUsed[position];
	}
	
	public void setClassUsed(boolean value, int position){
		classUsed[position] = value;
	}
	
	public void setLevel(int level){
		this.level = level;
	}
	
	public int getLevel(){
		return level;
	}
	
	//This code is for the unlockable classes
	public int returnClassCount(){
		int count = 0;
		for(int i = 0; i < Draws.unlockLevels.length;i++){
			if(Draws.unlockLevels[i] < (level+1)){
				count++;
			}
		}
		return count;
	}
	public int[] returnUnlockedClasses(){
		int[] holder = new int[returnClassCount()];
		int k = 0;
		for(int i = 0; i < Draws.unlockLevels.length;i++){
			if(Draws.unlockLevels[i] < (level+1)){
					holder[k] = Draws.classImages[i];
					k++;
			}
		}
		return holder;
	}
	public int[] returnUnlockedClassLevels(){
		int[] holder = new int[returnClassCount()];
		int k = 0;
		for(int i = 0; i < Draws.unlockLevels.length;i++){
			if(Draws.unlockLevels[i] < (level+1)){
					holder[k] = Draws.unlockLevels[i];
					k++;
			}
		}
		//System.out.println(level);
		return holder;
	}
	public int[] returnUnlockedClassNumbers(){
		int[] holder = new int[returnClassCount()];
		int k = 0;
		for(int i = 0; i < Draws.unlockLevels.length;i++){
			if(Draws.unlockLevels[i] < (level+1)){
					holder[k] = i;
					k++;
			}
		}
		//System.out.println(level);
		return holder;
	}
	public int[] returnDescriptionClasses(){
		int[] holder = new int[returnClassCount()];
		int k = 0;
		for(int i = 0; i < Draws.unlockLevels.length;i++){
			if(Draws.unlockLevels[i] < (level+1)){
					holder[k] = i;
					k++;
			}
		}
		return holder;
	}
	public int returnNewGamePositionClasses(int[] classes, int search){
		int index = 0;
		for(int i = 0; i < classes.length;i++){
			if(classes[i] == search){
				index = i;
				return index;
			}
		}
		return index;
	}
	//This code is for the unlockable levels
		public int returnLevelCount(){
			return level+2;
		}
		
		public int returnRaceCount(){
			if(level < 2){
				return 4;
			}else if(level <4){
				return 5;
			}else if(level < 6){
				return 6;
			}else if(level < 8){
				return 7;
			}else if (level < 10){
				return 8;
			}else{
				return 9;
			}
		}

}
